package me.jiatao.taobaotools.activity;

import android.content.Intent;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.text.TextUtils;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;

import me.jiatao.taobaotools.R;

public class FriendActivity extends AppCompatActivity {
    private EditText editText;
    private Button submit;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_friend);

        editText = (EditText) findViewById(R.id.edt_user_name);
        submit = (Button) findViewById(R.id.submit);

        handleSubmit();
    }

    private void handleSubmit() {
        submit.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (TextUtils.isEmpty(editText.getText())) {
                    editText.setError("微信号不能为空");
                    return;
                }
                shareTextToWechat();
            }
        });
    }

    private void shareTextToWechat() {
        String wxIDStr = editText.getText().toString();
        String fullInfo = String.format("<a href=\"weixin://contacts/profile/%s\">加好友</a>", wxIDStr);

        Intent wechatIntent = new Intent(Intent.ACTION_SEND);
        wechatIntent.setPackage("com.tencent.mm");
        wechatIntent.setType("text/plain");
        wechatIntent.putExtra(Intent.EXTRA_TEXT, fullInfo);
        startActivity(wechatIntent);

    }
}
